package cate.game.attr;

import cate.common.util.XT;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

@NoteClass("战斗影响因素")
public class PowerAttrPart {

    @NoteField("属性")
    public FightAttr attr = new FightAttr();

    @NoteField("技能id")
    public List<Integer> skills = new ArrayList<>();

    @NoteField("pvp生效的属性")
    public FightAttr pvpAttr = new FightAttr();

    @NoteField("pvp生效的技能")
    public List<Integer> pvpSkills = new ArrayList<>();

    @NoteField("附加战力估值")
    public long powerExt = 0;

    public void merge(PowerAttrPart part) {
        if (part == null) {
            return;
        }
        attr.add(part.attr);
        skills.addAll(part.skills);
        pvpAttr.add(part.pvpAttr);
        pvpSkills.addAll(part.pvpSkills);
        powerExt += part.powerExt;
    }

    public void addAttr(FightAttr attr) {
        this.attr.add(attr);
    }

    public void addPvpAttr(FightAttr attr){
        this.pvpAttr.add(attr);
    }

    public void addSkill(int skill){
        if(skill<=0){
            return;
        }
        this.skills.add(skill);
    }

    public void addSkills(List<Integer> skills){
        if(XT.isNotBlank(skills)){
            this.skills.addAll(skills);
        }
    }

    public void addPvpSkills(List<Integer> pvpSkills) {
        if (XT.isNotBlank(pvpSkills)) {
            this.pvpSkills.addAll(pvpSkills);
        }
    }

    /**
     * 读取
     */
    public void readFrom(PowerAttrPart tar) {
        if (tar == null) {
            return;
        }
        if (tar.attr != null) {
            this.attr = tar.attr.copy();
        }
        if (tar.skills != null) {
            this.skills = new ArrayList<>(tar.skills);
        }
        if (tar.pvpAttr != null) {
            this.pvpAttr = tar.pvpAttr.copy();
        }
        if (tar.pvpSkills != null) {
            this.pvpSkills = new ArrayList<>(tar.pvpSkills);
        }
        this.powerExt = tar.powerExt;
    }
}
